package cn.itsource.system.controller;


import cn.itsource.basic.utils.AjaxResult;
import cn.itsource.system.domain.Log;
import cn.itsource.system.query.MenuQuery;
import cn.itsource.system.service.LogService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/log")
public class LogController {
    @Autowired
    private LogService logService;


    @GetMapping
    public List<Log> fandAll(){
        return logService.findAll();
    }


    @DeleteMapping("/{id}")
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
            logService.delete(id);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "网络繁忙,请稍后重试");
        }
    }

    //分页+模糊查询
    @PostMapping
    public PageInfo<Log> pageQuery(@RequestBody MenuQuery query) {
        //前端接收参数：total，list
        return logService.pageQuery(query);
    }

    //批量删除
    @PatchMapping
    public AjaxResult patchdel(@RequestBody Long[] ids) {
        try {
            logService.patchdel(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false, "网络繁忙,请稍后重试");
        }
    }
    //导出文件
    @PatchMapping("/exportFile")
    public AjaxResult exportFile(@RequestBody Long[] ids){
        try {
            logService.exportFile(ids);
            return new AjaxResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new AjaxResult(false,"网络繁忙,请稍后重试");
        }
    }

}
